﻿@model LbangCMS.Areas.Admin.Models.ContentListModel
@{
    ViewBag.Title = "List";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}


@section head{
    <link href="~/Areas/Admin/Content/libs/zui/lib/datatable/zui.datatable.css" rel="stylesheet" />
    <link href="~/Areas/Admin/Content/libs/laypage/skin/laypage.css" rel="stylesheet" />
}
@section nav{
    <li><a href="#">新闻管理</a></li>
    <li class="active">新闻列表</li>
}

@section script{

    <script type="text/javascript">
        //表格标准化
        function to_datatable() {
            $('table.datatable').datatable({
                checkable: false,
                checkByClickRow: false,
                fixedHeader: false
            });
        }

        function setPager()
        {
            laypage({
                cont: 'pager',
                pages: $("#TotalPage").val(), //可以叫服务端把总页数放在某一个隐藏域，再获取。假设我们获取到的是18
                curr: $("#CurentPageIndex").val(),
                jump: function (e, first) { //触发分页后的回调
                    if (!first) { //一定要加此判断，否则初始时会无限刷新
                        reload_data(e.curr);
                    }
                }
            });
        }

        //重新加载数据
        function reload_data(pageIndex)
        {
            var url = '@Url.Action("List", "Content")' + "?PageIndex=" + pageIndex + "&r=" + Math.random();
            $.get(url, function (data) {
                      $("#view").html(data);
                      to_datatable()
                      setPager();
            })
        }

        function edit(id) {
            layer.open({
                type: 2,
                title: "编辑新闻信息",
                content: '@Url.Action("Edit", "Content")' + "?id=" + id,
                area: ['960px', '98%']
            });
        }

        function remove_item(id) {
            layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
                var url = '@Url.Action("Remove", "Content")';
                $.post(url, { id: id }, function (data) {
                    layer.msg("删除成功", { time: 800 });
                    reload_data($("#currentPageIndex").val());

                })
            });
        }

        function add_item() {

            layer.open({
                type: 2,
                title: "添加新闻",
                content: '@Url.Action("Edit", "Content")',
                area: ['960px', '98%']
            });
        }

        $(document).ready(function () {
            to_datatable();
            setPager();
        })
    </script>
}
<div class="panel">
    <div class="panel-heading">
        <button class="btn btn-primary" id="btnAdd" type="button" onclick="add_item()">添加新闻</button>
    </div>
    <div class="panel-body">
        <div id="view">
            @{Html.RenderPartial("_ListPartial", Model);}
        </div>
        <div class="text-center" id="pager"></div>
    </div>
</div>

